package com.ed100.sass.controller;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("msg")
public class ActiveMqController {

	@Autowired
	private JmsTemplate template;

	@Resource(name = "queueDestination")
	private Destination destination;
	
	@Resource(name = "topicDestination")
	private Destination topicDestination;

	@RequestMapping("send")
	public @ResponseBody String send() {
		String message = "hello activeMq";
		template.convertAndSend(destination, message);
		return "success";
	}
	
	@RequestMapping("send_topic")
	public @ResponseBody String sendToic() {
		String message = "hello activeMq";
		template.convertAndSend(destination, message);
		return "success";
	}
	
	@RequestMapping("send_topic_msg")
	public @ResponseBody String sendTopicMsg() {
		String message = "hello activeMq";
		template.convertAndSend(topicDestination, message);
		return "success";
	}
	
	@JmsListener(destination = "topic_dest")
	@SendTo("out.queue")
	public void receive(String text) {

		System.out.println("Consumer2收到的报文为:" + text);
	}

//	@JmsListener(destination = "spring-queue")
//	@SendTo("out.queue")
//	public void receive(String text) {
//
//		System.out.println("Consumer2收到的报文为:" + text);
//	}
}
